home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DDJMAG / DDJ9203.ZIP / OOPASM.ZIP / DIR.ASM < prev    next >
Assembly Source File  |  1990-07-11  |  7KB  |  273 lines

  1.     .MODEL    SMALL
  2.  
  3.     INCLUDE    equates.inc
  4.     INCLUDE    instance.inc
  5.     INCLUDE    messages.inc
  6.     INCLUDE    objects.inc
  7.  
  8.     MaxDirEntries    EQU    200        ;Maximum number of file names
  9.     MenuWidth    EQU    15        ;Menu width
  10.  
  11. IF1
  12.     INCLUDE    macros.mac
  13.     INCLUDE    objects.mac
  14. ENDIF
  15.  
  16.     EXTRN    disVertMenu:NEAR
  17.     EXTRN    makeActive:NEAR
  18.  
  19.     EXTRN    Clock:WORD
  20.     EXTRN    DBorder:WORD
  21.     EXTRN    HorzMenu:WORD
  22.     EXTRN    Menu:WORD
  23.     EXTRN    Self:WORD
  24.     EXTRN    Window:WORD
  25.  
  26.     .CODE
  27.  
  28. COMMENT    %
  29. ==============================================================================
  30. Sets Dir's instance variables with values handed down from the master.
  31.  
  32. =============================================================================%
  33. initDirVars    PROC    NEAR
  34.     push        Self
  35.     getInst$    ch,Row1,MasterObj    ;Get upper row from master
  36.     getInst        dh,Row2            ;Get lower row
  37.     getInst        dl,Col2            ;Get right column
  38.  
  39.     inc        ch            ;Add row offset
  40.     dec        dh            ;Subtract row offset
  41.     sub        dl,ColOffset        ;Subtract column offset
  42.  
  43.     setInst        Row1,ch,Dir        ;Set upper row
  44.     setInst        Row2,dh            ;Set lower row
  45.     setInst        Col2,dl            ;Set right column
  46.  
  47.     sub        dl,MenuWidth        ;Subtract menu width
  48.     setInst        Col1,dl            ;Set left column
  49.     setInst        InxPtr,0,,2        ;Clear index pointer
  50.     pop        Self
  51.     ret
  52. initDirVars    ENDP
  53.  
  54.  
  55.  
  56. COMMENT    %
  57. ==============================================================================
  58. Create directory menu of all files in current directory.
  59.  
  60. =============================================================================%
  61. createDirMenu    PROC    NEAR
  62.     getInst        dx,?ReadDir,Dir        ;Directory already read
  63.     identity    dx,cdm1            ;Exit if not Nil
  64.     call        setDTA            ;Setup data transfer area
  65.     lea        dx,FilePattern        ;Pass ptr to search pattern
  66.     call        findFirst        ;Find first occurence of file
  67.     call        findRest        ;Find rest of files
  68.     call        makeMenu        ;Make directory menu
  69.     setInst        ?ReadDir,0,Dir,2    ;Flag as haven been read
  70. cdm1:    ret
  71. createDirMenu    ENDP
  72.  
  73.  
  74.  
  75. COMMENT    %
  76. ==============================================================================
  77. Setups data transfer area.
  78.  
  79. =============================================================================%
  80. setDTA    PROC    NEAR
  81.     lea        dx,DTA            ;Pass DTA address
  82.     mov        ah,1Ah            ;Pass service number
  83.     int        DosInt            ;DOS interrupt
  84.     ret
  85. setDTA    ENDP
  86.  
  87.  
  88.  
  89.     PUBLIC    findFirst
  90. COMMENT    %
  91. ==============================================================================
  92. Finds first occurence of file that matches file pattern.
  93.  
  94. Passed: dx - File pattern to search for
  95.  
  96. =============================================================================%
  97. findFirst    PROC    NEAR
  98.     mov        cx,111111b        ;All file attributes
  99.     mov        ah,4Eh            ;Pass service number
  100.     int        DosInt            ;DOS interrupt
  101.     ret
  102. findFirst    ENDP
  103.  
  104.  
  105.  
  106. COMMENT    %
  107. ==============================================================================
  108. Finds rest of files that matches file pattern.
  109.  
  110. =============================================================================%
  111. findRest    PROC    NEAR
  112.     xor        cx,cx            ;Clear counter
  113.     cld                    ;Clear direction flag
  114.     lea        di,DirBuf        ;Get destination addr
  115.     lea        si,FileName        ;Get source addr
  116. fndr1:    call        movString        ;Copy from source to dest
  117.     mov        ah,4Fh            ;Pass service number
  118.     int        DosInt            ;DOS interrupt
  119.     inc        cx            ;Increment count
  120.     jnc        fndr1            ;Jump if more matches
  121.  
  122.     dec        cx            ;Zero based counting
  123.     mov        Bptr[di],Nil        ;Mark end of file list
  124.     ret
  125. findRest    ENDP
  126.  
  127.  
  128.  
  129. COMMENT    %
  130. ==============================================================================
  131. Copies an ASCIIZ string from source to destination. Adds blanks to both ends.
  132.  
  133. Passed:    di - Destination addresss
  134.     si - Source address
  135.  
  136. =============================================================================%
  137. movString    PROC    NEAR
  138.     push        si
  139.     mov        Bptr[di],Space        ;Copy space into first byte
  140. mvs1:    inc        di            ;Point to next byte
  141.     lodsb                    ;Get byte from source
  142.     zero        al,mvs2            ;Is it zero? - Jump
  143.     mov        Bptr[di],al        ;Else - Copy to destination
  144.     jmp        mvs1            ;Continue
  145. mvs2:    mov        Bptr[di],Space        ;Copy space to destination
  146.     mov        Bptr[di+1],0        ;Copy zero into last byte
  147.     add        di,2            ;Point to next open byte
  148.     pop        si
  149.     ret
  150. movString    ENDP
  151.  
  152.  
  153.  
  154. COMMENT    %
  155. ==============================================================================
  156. Makes a menu of directory entries.
  157.  
  158. =============================================================================%
  159. makeMenu    PROC    NEAR
  160.     lea        si,DirBuf        ;Get ptr to directory list
  161.     lea        di,DirTbl        ;Get ptr to directory menu
  162. mkm1:    mov        al,Bptr[si]        ;Get char
  163.     null        al,mkm2            ;No more files? - Exit
  164.     call        fillEntry        ;Else - Fill in a menu entry
  165.     jmp        mkm1            ;Continue
  166. mkm2:    mov        Wptr[di],Nil        ;Mark end of menu
  167.     ret
  168. makeMenu    ENDP
  169.  
  170.  
  171.  
  172. COMMENT    %
  173. ==============================================================================
  174. Fills in a menu entry.
  175.  
  176. Passed:    di - Pointer to 4-byte menu entry.
  177.     si - Pointer to first char of file name.
  178.  
  179. Passes:    di - Pointer to next menu entry.
  180.     si - Pointer to first char of next file name.
  181.  
  182. =============================================================================%
  183. fillEntry    PROC    NEAR
  184.     mov        Wptr[di],0        ;Save row/col of menu item
  185.     mov        Wptr[di+2],si        ;Save ptr to file name
  186.     add        di,4            ;Point to next menu entry
  187. fll1:    lodsb                    ;Get char
  188.     notZero        al,fll1            ;More chars in name? - Loop
  189.     ret
  190. fillEntry    ENDP
  191.  
  192.  
  193.  
  194. IF Dbug
  195.     PUBLIC    copyTxtPtr
  196. ENDIF
  197. COMMENT    %
  198. ==============================================================================
  199. Stuffs the currently hilited menu item into memory for use by master object.
  200. Clears the menu index pointer to avoid normal Menu,Select activity.
  201.  
  202. =============================================================================%
  203. copyTxtPtr    PROC    NEAR
  204.     getInst        bx,InxPtr,Self        ;Get index pointer
  205.     getInst        di,MenuPtr        ;Get menu pointer
  206.     mov        bx,Wptr[di+bx+2]    ;Get text ptr
  207.     inc        bx            ;Skip leading space
  208.     setInst        TxtPtr,bx        ;Copy it to text ptr inst var
  209.     setInst        InxPtr,Nil,,2        ;Clear index pointer
  210.     ret
  211. copyTxtPtr    ENDP
  212.  
  213.  
  214.  
  215.     .DATA
  216.  
  217.     PUBLIC    FileAttr
  218.     PUBLIC    FileTime
  219.     PUBLIC    FileDate
  220.     PUBLIC    FileSize
  221.     PUBLIC    FileName
  222. DTA        DB    21 DUP (0)        ;Reserved
  223. FileAttr    DB    0            ;File attribute
  224. FileTime    DW    0            ;File time
  225. FileDate    DW    0            ;File date
  226. FileSize    DD    0            ;File size
  227. FileName    DB    64 DUP (0)        ;File name
  228. DirBuf        DB    MaxDirEntries*15 DUP (0)
  229. IF Dbug
  230.     PUBLIC    DirTbl
  231. ENDIF
  232. DirTbl        DB    MaxDirEntries*4 DUP (Nil)
  233. FilePattern    DB    "*.*",0            ;Search for all files
  234.  
  235. defMsg    Dir,\
  236.     Refresh,\
  237.     <initDirVars,createDirMenu,disVertMenu>
  238.  
  239. defMsg    Dir,\
  240.     Read,\
  241.     <makeActive,,>
  242.  
  243. defMsg    Dir,\
  244.     Next,\
  245.     <makeActive,,>
  246.  
  247. defMsg    Dir,\
  248.     Prev,\
  249.     <makeActive,,>
  250.  
  251. defMsg    Dir,\
  252.     Select,\
  253.     <copyTxtPtr,,>
  254.  
  255. defObj    Dir,\
  256.     <Window,DBorder,Menu>,\
  257.     <Row1,1,10,\
  258.     Col1,1,53,\
  259.     Row2,1,15,\
  260.     Col2,1,63,\
  261.     Color,1,31h,\
  262.     Unused,1,Nil,\
  263.     ?ReadDir,2,Nil,\
  264.     InxPtr,2,0,\
  265.     MasterObj,2,Nil,\
  266.     DispTbl,2,Nil,\
  267.     MenuPtr,2,DirTbl>,\
  268.     <Refresh,Read,Next,Prev,Select,Clear,ScrollUp,ScrollDown,Hilite>
  269.  
  270.  
  271.  
  272.     END
  273.